"""
. 当前目录
.. 父级目录

文件操作最后都需要加上close关闭；除非使用with关键字
"""

# 读取当前目录文件
f1 = open("./PrintSample.py","r",encoding="utf-8")
for line in f1:
    print(line.strip())
f1.close()

# 读取同级目录文件
f2 = open("../modules/fn_proxy.py.py", "r", encoding="utf-8")
print(f2.read())
f2.close()

f3 = open("../../static/uploads/content.txt", "w", encoding="utf-8")
f3.write("xbox")
f3.close()

f4 = open("../../static/uploads/content.txt", "a", encoding="utf-8")
f4.write("ps")
f4.close()

print("-----------------------------------------------------------------------------")

# 将file1内容，读取并修改，最后写入到file2中
# 使用"\" 连接命令
with open(file="../modules/fn_proxy.py.py", mode="r", encoding="utf-8") as file1, \
        open(file="../../static/uploads/content.txt", mode="w", encoding="utf-8") as file2:
    for line in file1:
       line = line.replace('eric','bill')
       file2.write(line)